<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 2017/8/22
 * Time: 19:10
 * 昵称'。'更改脚本
 */
class ChangeNicknameHandler  extends ScriptBase{
    public $paijuRedis;
    public function logic()
    {
        set_time_limit(0);
        $mysql = $this->mysql('game');
        $sql = "select uid from d_user where nickname='。'";//获取uids
        $result=$mysql->query($sql);
        $a=0;
        $b=0;
        if($result) {
            $result_data = $mysql->fetch_all();
            foreach ($result_data as $k=>$val){
                $fields = array(
                    'uid','nickname'
                );

                $redis_userinfo=$this->redis('user_info')->hMget( 'U:'.$val['uid'], $fields );
                if($redis_userinfo['uid'] && $redis_userinfo['nickname']){
                    if($redis_userinfo['nickname']=="。"){
                        $a++;
                    }
                    $nickname=self::replaceSpecialChar($redis_userinfo['nickname']);
                    $sql_updata=sprintf("UPDATE `d_user` SET nickname='%s' WHERE uid=%u",$nickname,$redis_userinfo['uid']);
                    $mysql->query($sql_updata);
                }else{
                    $b++;
                }
            }
            echo 'redis库存昵称为“。”用户数量：'.$a.'-----'."redis丢失用户数量：".$b;
        }
    }

    public function replaceSpecialChar($strParam){
        $regex = "/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\"|\`|\-|\=|\\\|\|/";
        return preg_replace($regex,"",$strParam);
    }
}